import { ref } from 'vue'

import { menuApi } from '@/apis'

import type { CheckedKeys } from '../types'

export function useMenuTree() {
  const menuTree = ref([] as ITreeNode[])
  const treeLoading = ref(false)
  const checkedKeys = ref({
    checked: [] as string[],
    halfChecked: [] as string[]
  } as CheckedKeys)

  async function getMenuTree() {
    treeLoading.value = true

    menuTree.value = await menuApi.getMenuTree()

    treeLoading.value = false
  }

  return {
    menuTree,
    treeLoading,
    checkedKeys,
    getMenuTree
  }
}
